package com.medical.admin.hospital.controller;
import com.medical.admin.hospital.common.dto.DepartmentDto;
import com.medical.admin.hospital.common.vo.DepartmentVo;
import com.medical.admin.hospital.common.vo.DownMenu;
import com.medical.admin.hospital.common.vo.PageVo;
import com.medical.admin.hospital.service.ComboService;
import com.medical.admin.hospital.service.DepartmentService;
import com.qf.medical.response.ResponseEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
 * @description: 科室信息管理
 * @author: LuAn
 * @date: 2024/4/29
 */
@Api("科室管理Api在线文档")
@RestController
@RequestMapping("/department")
public class DepartmentController {
    @Resource
    private DepartmentService departmentService;
    @Resource
    private ComboService comboService;

    @GetMapping("/page")
    @ApiOperation("分页查询科室信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "departmentName",value = "科室名称"),
            @ApiImplicitParam(name = "pageNum",value = "当前页"),
            @ApiImplicitParam(name = "pageSize",value = "页大小")})
    public ResponseEntity<PageVo<DepartmentVo>> list(String departmentName,@RequestParam(defaultValue = "1")
    int pageNum, @RequestParam(defaultValue = "10") int pageSize){
        return ResponseEntity.success(departmentService.list(departmentName,pageNum,pageSize));
    }

    @PostMapping("/add")
    @ApiOperation("新增科室信息")
    @ApiImplicitParam(name = "departmentDto",value = "科室信息对象")
    public ResponseEntity<Integer> add(@RequestBody DepartmentDto departmentDto){
        return ResponseEntity.success(departmentService.insert(departmentDto));
    }

    @ApiOperation("修改科室信息")
    @PutMapping("/modify")
    @ApiImplicitParam(name = "departmentDto" ,value = "科室信息")
    public ResponseEntity<Integer> modify(@RequestBody DepartmentDto departmentDto){
        return ResponseEntity.success(departmentService.update(departmentDto));
    }

    @ApiOperation("删除科室信息")
    @DeleteMapping("/remove")
    @ApiImplicitParam(name = "departmentId" ,value = "科室Id")
    public ResponseEntity<Integer> remove(@NotNull Long departmentId){
        return ResponseEntity.success(departmentService.delete(departmentId));
    }

    @ApiOperation("查询科室详情")
    @GetMapping("/detail")
    @ApiImplicitParam(name = "departmentId" ,value = "科室ID")
    public ResponseEntity<DepartmentVo> detail(@NotNull Long departmentId){
        return ResponseEntity.success(departmentService.select(departmentId));
    }

    @ApiOperation("下拉展示科室一级信息")
    @GetMapping("/showParent")
    public ResponseEntity<List<DepartmentVo>> showParent(){
        return ResponseEntity.success(departmentService.showParent());
    }

    @ApiOperation("下拉展示科室二级信息")
    @GetMapping("/showDetail")
    @ApiImplicitParam(name = "parentId",value = "上级目录")
    public ResponseEntity<DepartmentVo> showDepartments(@RequestParam(defaultValue = "1") Long parentId){
        return ResponseEntity.success(departmentService.showDepartments(parentId));
    }

    @ApiOperation("下拉展示医院信息")
    @GetMapping("/showHospital")
    public ResponseEntity<DownMenu> showHospital(){
        return ResponseEntity.success(comboService.selectHospital());
    }
}
